Ext.define('PHT.CheckURLAddURLForm', {
    extend: 'Ext.form.Panel',
    alias: 'widget.checkurladdurlform',

    requires: ['Ext.form.field.Text'],
    ismodified: false,

    initComponent: function(){
        //this.addEvents('create');
        Ext.apply(this, {
            activeRecord: null,
            //iconCls: 'icon-user',
            frame: true,
            //title: 'Add a URL',
            defaultType: 'textfield',
            bodyPadding: 5,
            fieldDefaults: {
                anchor: '100%',
                labelAlign: 'right'
            },
            items: [
				{
	                fieldLabel: 'URL',
	                name: 'name',
	                allowBlank: false,
	                vtype: 'url'
                }               
            ],
            dockedItems: [{
                xtype: 'toolbar',
                dock: 'bottom',
                ui: 'footer',
                items: ['->', {
                    //iconCls: 'icon-save',
                    itemId: 'save',
                    text: 'Save',
                    //disabled: true,
                    scope: this,
                    handler: this.onSave
                },{
                    iconCls: 'icon-reset',
                    text: 'Reset',
                    scope: this,
                    handler: this.onReset
                }]
            }]
        });
        this.callParent();
    },

    setActiveRecord: function(record){
        this.activeRecord = record;
//        if (record) {
//            this.down('#save').enable();
//            this.getForm().loadRecord(record);
//        } else {
//            this.down('#save').disable();
//            this.getForm().reset();
//        }
    },

    onSave: function(){
    	var store = Ext.data.StoreManager.lookup('available-store');
    	var form = this.getForm();
    	if(form.isValid()){
    		if(!this.ismodified){
    			store.insert(0,form.getValues());
    		}else{
    			form.updateRecord(this.activeRecord);
    		}   		
    		var win = Ext.getCmp('addurl-win');
    		win.close();
    	}else{
    		Ext.MessageBox.alert('invalid url address.');
    	}  	
    },

    onReset: function(){
        this.setActiveRecord(null);
        this.getForm().reset();
    }
});